import { EntitySchema } from '@mikro-orm/core';

export class PersonalAccessTokens {
  id!: string;
  tokenableType!: string;
  tokenableId!: string;
  name!: string;
  token!: string;
  abilities?: string;
  lastUsedAt?: Date;
  createdAt?: Date;
  updatedAt?: Date;
}

export const PersonalAccessTokensSchema = new EntitySchema({
  class: PersonalAccessTokens,
  indexes: [
    { name: 'personal_access_tokens_tokenable_type_tokenable_id_index', properties: ['tokenableType', 'tokenableId'] },
  ],
  uniques: [
  ],
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    tokenableType: { type: 'string', length: 255 },
    tokenableId: { type: 'string', columnType: 'bigint' },
    name: { type: 'string', length: 255 },
    token: { type: 'string', length: 64, unique: 'personal_access_tokens_token_unique' },
    abilities: { type: 'string', columnType: 'text', nullable: true },
    lastUsedAt: { type: 'Date', length: 0, nullable: true },
    createdAt: { type: 'Date', length: 0, nullable: true },
    updatedAt: { type: 'Date', length: 0, nullable: true },
  },
});
